﻿using Rhino;
using Rhino.Commands;
using System;
using YangTools.Realization;

namespace YangTools
{
    public class BlockSubObjectsRemoveCommand : Command
    {
        static BlockSubObjectsRemoveCommand _instance;
        public BlockSubObjectsRemoveCommand()
        {
            _instance = this;
        }

        ///<summary>The only instance of the BlockSubObjectsRemoveCommand command.</summary>
        public static BlockSubObjectsRemoveCommand Instance
        {
            get { return _instance; }
        }

        public override string EnglishName
        {
            get { return "RemoveFromBlock"; }
        }

        /// <summary>
        /// 从图块中移除物体
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetOption();
            var t = new Rhino.Input.Custom.OptionToggle(true, "否", "是");
            go.AddOptionToggle("保留", ref t);
            go.AcceptNothing(true);
            go.SetCommandPrompt("是否保留删除的物体");
            var r = go.Get();

            bool keepRemoveObjects = true;
            if (r == Rhino.Input.GetResult.Option) keepRemoveObjects = t.CurrentValue;

            var rfb = new BlockSubObjects();
            rfb.RemoveFromBlock(keepRemoveObjects);
            return Result.Success;
        }
    }
}